package com.wanglei.ssm.dao;

import com.wanglei.ssm.domain.Orders;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 订单数据操作接口
 *
 * @author wl
 */
public interface OrdersDao {

    /**
     * 查询所有订单信息
     *
     * @return 订单信息集合
     * @throws Exception e
     */
    @Select("select * from orders")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(column = "productId", property = "product", one = @One(select =
                    "com.wanglei.ssm.dao.ProductDao.findById"))

    })
    List<Orders> findAll() throws Exception;

    /**
     * 根据id查询订单信息
     *
     * @param id 订单id
     * @return 订单信息
     * @throws Exception e
     */
    @Select("select * from orders where id = #{id}")
    @Results({
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(column = "productId", property = "product", one = @One(select = "com.wanglei.ssm.dao.ProductDao.findById")),
            @Result(column = "id", property = "travellers", many = @Many(select = "com.wanglei.ssm.dao.TravellersDao.findByOrdersId")),
            @Result(column = "memberId", property = "member", one = @One(select = "com.wanglei.ssm.dao.MemberDao.findById"))
    })
    Orders findById(String id) throws Exception;
}
